#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time         : 17-12-13 下午6:47
# @Author       : xiaohan
# @File         : mongoUtils.py
# @desc         : 

import pymongo


def get_database_connect():
    mc = pymongo.MongoClient("101.200.59.101", 27017)
    try:
        db = mc.sqlData
        db.authenticate('dsg', 'dsg@2017')
        return db
    finally:
        mc.close()


db = get_database_connect()

if __name__ == '__main__':
    query = [{
        "$lookup": {
            "from": "SecuMain",
            "localField": "SecuCode",
            "foreignField": "SecuCode",
            "as": "stuffFromRight"
        }},
        {"$match": {"SecuCode": "601186"}}
        , {"$project": {"stuffFromRight": 1, "SecuMarket": 1, "_id": 0}}
    ]
    ret = list(db.company_compliance_info.aggregate(query))
    print(ret)
